<extend name="Public:main" />

<block name="style">
<style>.red{color:#f00}#message{white-space:pre-wrap;word-wrap:break-word;word-break:break-all;font-family:'Courier New','Microsoft YaHei','SimSun'}</style>
</block>

<block name="container">
<p>SQL语句：</p>
<textarea id="textarea" class="form-control" rows="10" placeholder="{$placeholder}" style="max-width:99%">select count(id) from wu_blog</textarea>
<br />
<button id="submit" class="btn btn-sm btn-success">提交</button>
<div id="message">&nbsp;<br />&nbsp;</div>
</block>

<block name="script">
<script>
$(function(){
	$('#submit').click(function(){
		var sql = $('#textarea').val();
		$.ajax({
			url: '__APP__/Sql/query',
			data: {
				sql: sql,
			},
			type: 'POST',
			cache: false,
			dataType: 'JSON',
			success: function(data){
				$('#message').html('<span class="red">影响行数：</span>' + data.execute + '<br /><span class="red">查询语句：</span>' + data.sql + '<br /><span class="red">查询结果：</span>' + data.query);
			},
			error: function(){
				$('#message').html('<span class="red">SQL语句错误<br />请检查重试</span>');
			}
		});
	});
});
</script>
</block>